package com.qf.mapper;

import com.qf.dto.ContractorDto;
import com.qf.model.Contractor;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

@Mapper
public interface ContractorMapper {

    @Results(id = "contractorMap",value = {
            @Result(column = "cid",property = "cid"),
            @Result(column = "cname",property = "cname"),
            @Result(column = "updatetime",property = "updatetime"),
            @Result(column = "cid",property = "projects",many =
                    //select代表关联查询
            @Many(select = "com.qf.mapper.ProjectMapper.findByCid",fetchType = FetchType.EAGER)
           //一对多映射
            )

    })

    @Select("select * from contractor where cid=#{cid} and status =1")
    Contractor findByCid(String cid);

    @Select("Select * from contractor where status =1 limit #{currentPage},#{pageSize}")
    List<Contractor> findPage(@Param("currentPage")Integer currentPage, @Param("pageSize") Integer pageSize);

    @Select("select count(*) from contractor where status=1")
    long count();

    @Insert("insert into contractor (cid,cname,updatetime) values(#{cid},#{cname},#{updatetime})")
    int addContractor(Contractor contractor);

    @Select("select * from contractor where cid=#{cid} and status=1")
    ContractorDto findByCidDto(String cid);

    @Update("update contractor set cname=#{cname},updatetime=#{updatetime} where cid =#{cid}")
    int edit(ContractorDto contractorDto);

    @Update("update contractor set status =0 where cid=#{cid}")
    int delByCid(String cid);
    @Select("select * from contractor where status=1")
    List<Contractor> findAll();
}
